package multithreading;

public class ticketRunnable implements Runnable {
    int ticket = 0;

    @Override
    public void run() {
        while (true) {
            try {
                if (soldTicket())
                    break;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

    public synchronized boolean soldTicket() throws InterruptedException {
        if (ticket < 100) {
            Thread.sleep(10);
            ticket++;
            System.out.println(Thread.currentThread().getName() + "@" + ticket);
            return false;
        } else {
            return true;
        }
    }
}
